package cn.itcast.service.cargo.impl;



import cn.itcast.dao.cargo.FinanceDao;
import cn.itcast.domain.cargo.Finance;
import cn.itcast.domain.cargo.FinanceExample;
import cn.itcast.service.cargo.FinanceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class FinanceServiceImpl implements FinanceService {

    @Autowired
    private FinanceDao  financeDao;
    /**
     * 查询所有
     *
     * @param loginCompanyId
     * @param pageNum
     * @param pageSize
     */
    @Override
    public PageInfo<Finance> findAll(String loginCompanyId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        FinanceExample financeExample = new FinanceExample();
        financeExample.createCriteria().andCompanyIdEqualTo(loginCompanyId);
        List<Finance> list = financeDao.selectByExample(financeExample);

        PageInfo<Finance> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    /**
     * 根据id查找财务报运单
     *
     * @param financeOrderId
     */
    @Override
    public Finance findBySOId(String financeOrderId) {
        return financeDao.selectByPrimaryKey(financeOrderId);
    }

    /**
     * 增加财务保运单
     *
     * @param finance
     */
    @Override
    public void addFinance(Finance finance) {
        finance.setFinanceId(UUID.randomUUID().toString());
        financeDao.insertSelective(finance);
    }

    /**
     * 查询本公司的所有财务保运单
     *
     * @param loginCompanyId
     */
    @Override
    public List<Finance> findFinance(String loginCompanyId) {
        FinanceExample financeExample = new FinanceExample();
        financeExample.createCriteria().andCompanyIdEqualTo(loginCompanyId);
        return financeDao.selectByExample(financeExample);
    }
}
